#include "src/gui/qt/mainwindow.h"
#include <QTextBrowser>
#include <QTextCodec>
#include <QMessageBox>
#include <QFileDialog>
#include <QStatusBar>
#include <QMenuBar>
#include <QFile>
#include <QDir>
#include <QDebug>
#include "src/gui/qt/subwindow.h"
#include "src/core/workspace/workspace.h"
#include "src/core/generic/parser.h"
#include "src/gui/qt/loggerwarningdialog.h"
#include "src/core/generic/translator.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
  loadSettings();
  createWidgets();
  createActions();
/*  switch(menuType)
  {
  case ClassicalMenu:
    setClassicalMenu();
    break;
  case ProfessionalMenu:
    setProfessionalMenu();
    break;
  }*/
  createClassicalMenu();
  createToolbars();
  createStatusBar();
}

MainWindow::~MainWindow()
{
  // all QObjects are deleted by Qt's backend, except unparented menus
}

void MainWindow::loadSettings()
{
  // temporary version. will be replaced by real restoring.
  menuType = ClassicalMenu;
  selectionBehaviuorFlags = Append;
  toolBarFlags = General | WindowControl | Edit ;
  widgetFlags = LogWidget;
  tabbedViewFlag = false;
  cascadeViewFlag = true;
}

void MainWindow::saveSettings()
{
  // temporary version. will be replaced by real saving.
}

void MainWindow::createWidgets()
{
  extern Translator translator;
  setCentralWidget(mdiArea = new QMdiArea);
  statusLabel = new QLabel(translator.qString("Ready", "status label text"));
  loggerWidgetDock = new QDockWidget(translator.qString("Logger", "logger dock title"));
  loggerWidgetDock->setWidget(  loggerWidget = new LoggerWidget);
  loggerWidgetDock->setVisible(widgetFlags.testFlag(LogWidget));
  addDockWidget(Qt::BottomDockWidgetArea, loggerWidgetDock);
  connect(loggerWidgetDock, SIGNAL(visibilityChanged(bool)), this, SLOT(viewLoggerWidget(bool)));

  helpBrowser = 0; // will be created when needed
}

void MainWindow::newSession() {};

void MainWindow::createWidgetForWsp(int wspId, std::string name)
{
  ViewWidget *widget = new ViewWidget(wspId);
  SubWindow *subWindow = new SubWindow(mdiArea->viewMode());
  subWindow->setWidget(widget);
  subWindow->setWorkspace(wspId);
  wspWidgets.insert(std::pair<int, ViewWidget*>(wspId, widget));
  mdiArea->addSubWindow(subWindow);
  subWindow->setWindowTitle(QString::fromStdString(name));
  subWindow->show();

  connect(subWindow, SIGNAL(savingRequested(int)), this, SLOT(saveDocument(int)));
  QAction *action = new QAction(QString::fromStdString(name), this);
  action->setCheckable(true);
  action->setChecked(true);
  windowMenu->addAction(action);
  connect(action, SIGNAL(triggered(bool)), subWindow, SLOT(setVisible(bool)));
  connect(subWindow, SIGNAL(visibilityChanged(bool)), action, SLOT(setChecked(bool)));
  connect(subWindow, SIGNAL(closed(int)), this, SLOT(removeWorkspace(int)));
  connect(subWindow, SIGNAL(destroyed()), action, SLOT(deleteLater()));
}

void MainWindow::newLogEntry(const LoggerRecord& record)
{
  if (loggerWidget)
  {
    loggerWidget->addRecord(record);
  }
}

void MainWindow::warnUser(const Logger::container_type& container)
{
  if (container.empty()) return;
  LoggerWarningDialog dialog(container, this);
  if (!dialog.isEmpty()) dialog.exec();
}

void MainWindow::open()
{
  extern Translator translator;
  QStringList filenames = QFileDialog::getOpenFileNames(this, translator.qString("VizMF : Open", "Open file dialog title"), QDir::homePath(), translator.qString("VizMF files (*.vmf)\nTripos mol2 files (*.mol2)\nESP files (*.esp)\nAll files (*.*)", "open files filter"));
  for (QStringList::iterator i = filenames.begin(), e = filenames.end(); i != e; ++i)
  {
    controller->open(i->toStdString());
  }
};

void MainWindow::setWspSaved(const int wspId, const bool saved)
{
  QList<QMdiSubWindow *> list = mdiArea->subWindowList();
  for (QList<QMdiSubWindow *>::iterator i = list.begin(), e = list.end(); i != e; ++i )
  {
    if (((SubWindow*)(*i))->wspId() == wspId)
    {
      (*i)->setWindowModified(!saved);
      break;
    }
  }
}

void MainWindow::createStatusBar()
{
  statusBar()->addWidget(statusLabel);
}

void MainWindow::setStatusText(const std::string& text)
{
  statusLabel->setText(QString::fromStdString(text));
}

void MainWindow::createToolbars()
{
  extern Translator translator;
  generalToolBar = new QToolBar(translator.qString("General", "toolbar's name"));
  generalToolBar->addAction(newDocumentAction);
  generalToolBar->addAction(openAction);
  generalToolBar->addAction(saveAction);
  generalToolBar->addAction(saveAllAction);
  addToolBar(generalToolBar);
  editToolBar = new QToolBar(translator.qString("Edit", "toolbar's name"));
  editToolBar->addAction(undoAction);
  editToolBar->addAction(redoAction);
  editToolBar->addSeparator();
  editToolBar->addAction(copyAction);
  editToolBar->addAction(cutAction);
  editToolBar->addAction(pasteAction);
  editToolBar->addAction(removeAction);
  addToolBar(editToolBar);
  windowControlToolBar = new QToolBar(translator.qString("Window Control", "toolbar's name"));
  windowControlToolBar->addAction(cascadeWindowsAction);
  windowControlToolBar->addAction(tileWindowsAction);
  addToolBar(windowControlToolBar);
}

void MainWindow::createClassicalMenu()
{
  extern Translator translator;
  fileNewMenu = new QMenu(translator.qString("New", "submenu name"));
  fileNewMenu->setIcon(QIcon(":/actions/document-new.png"));
  fileNewMenu->addAction(newSessionAction);
  fileNewMenu->addAction(newDocumentAction);
  fileRecentMenu = new QMenu(translator.qString("Recent", "submenu name"));
  fileRecentMenu->setIcon(QIcon(":/actions/document-open-recent.png"));
  for (int i = 0; i < 5; i++)
  {
    if ( recentAction[i] ) fileRecentMenu->addAction(recentAction[i]);
  }
  fileImportMenu = new QMenu(translator.qString("Import", "submenu name"));
  fileImportMenu->addAction(importStructureAction);
  fileImportMenu->addAction(importLatticeAction);
  fileImportMenu->addAction(importFieldAction);
  fileImportMenu->addAction(importStyleAction);
  fileImportMenu->addAction(importSurfaceAction);
  fileExportMenu = new QMenu(translator.qString("Export", "submenu name"));
  fileExportMenu->addAction(exportStructureAction);
  fileExportMenu->addAction(exportLatticeAction);
  fileExportMenu->addAction(exportFieldAction);
  fileExportMenu->addAction(exportStyleAction);
  fileExportMenu->addAction(exportSurfaceAction);
  fileExportMenu->addSeparator();
  fileExportMenu->addAction(exportImageAction);
  fileMenu = new QMenu(translator.qString("&File", "menu name"));
  fileMenu->addMenu(fileNewMenu);
  fileMenu->addAction(openAction);
  fileMenu->addMenu(fileRecentMenu);
  fileMenu->addSeparator();
  fileMenu->addAction(saveAction);
  fileMenu->addAction(saveAllAction);
  fileMenu->addSeparator();
  fileMenu->addMenu(fileImportMenu);
  fileMenu->addMenu(fileExportMenu);
  fileMenu->addSeparator();
  fileMenu->addAction(closeAction);
  fileMenu->addAction(exitAction);
  menuBar()->addMenu(fileMenu);
  editInsertMenu = new QMenu(translator.qString("Insert", "submenu name"));\
  editInsertMenu->addAction(insertArrowAction);
  editInsertMenu->addAction(insertLineAction);
  editInsertMenu->addAction(insertLabelAction);
  editInsertMenu->addAction(insertTextAction);
  editTransformMenu = new QMenu(translator.qString("Transform", "submenu name"));
  editTransformMenu->addAction(rotateAction);
  editTransformMenu->addAction(translateAction);
  editTransformMenu->addAction(scaleAction);
  editStyleMenu = new QMenu(translator.qString("Style", "submenu name"));
  editStyleMenu->addAction(setBSAction);
  editStyleMenu->addAction(setCpkAction);
  editStyleMenu->addAction(setWireframeAction);
  editMenu = new QMenu(translator.qString("&Edit", "menu name"));
  editMenu->addAction(undoAction);
  editMenu->addAction(redoAction);
  editMenu->addSeparator();
  editMenu->addAction(copyAction);
  editMenu->addAction(cutAction);
  editMenu->addAction(pasteAction);
  editMenu->addAction(removeAction);
  editMenu->addSeparator();
  editMenu->addMenu(editInsertMenu);
  editMenu->addSeparator();
  editMenu->addMenu(editTransformMenu);
  editMenu->addSeparator();
  editMenu->addMenu(editStyleMenu);
  editMenu->addSeparator();
  editMenu->addAction(showAction);
  editMenu->addAction(hideAction);
  menuBar()->addMenu(editMenu);
  selectionCriterialMenu = new QMenu(translator.qString("By Criterion", "submenu name"));
  selectionCriterialMenu->addAction(selectNearestAction);
  selectionModeMenu = new QMenu(translator.qString("Mode", "submenu name"));
  selectionModeMenu->addAction(selectionAppendAction);
  selectionModeMenu->addAction(selectionReplaceAction);
  selectionMenu = new QMenu(translator.qString("Selection", "menu name"));
  selectionMenu->addAction(selectAllAction);
  selectionMenu->addAction(unselectAllAction);
  selectionMenu->addAction(invertSelectionAction);
  selectionMenu->addSeparator();
  selectionMenu->addMenu(selectionCriterialMenu);
  selectionMenu->addSeparator();
  selectionMenu->addMenu(selectionModeMenu);
  selectionMenu->addSeparator();
  selectionMenu->addAction(itemInspectorAction);
  menuBar()->addMenu(selectionMenu);
  toolsLoggingMenu = new QMenu(translator.qString("Logging", "submenu name"));
  toolsLoggingMenu->addAction(loggingStartAction);
  toolsLoggingMenu->addAction(loggingPauseAction);
  toolsLoggingMenu->addAction(loggingStopAction);
  toolsLoggingMenu->addSeparator();
  toolsLoggingMenu->addAction(generateScriptAction);
  toolsCompareMenu = new QMenu(translator.qString("Compare structures", "submenu name"));
  toolsCompareMenu->addAction(compareStructuresSyncRotationAction);
  toolsCompareMenu->addAction(compareStructuresOneWindowAction);
  toolsInterpolateFieldMenu = new QMenu(translator.qString("Interpolate field", "submenu name"));
  toolsInterpolateFieldMenu->addAction(interpolateFieldLinearAction);
  toolsInterpolateFieldMenu->addAction(interpolateFieldCubicSplinesAction);
  toolsGenFieldFieldMenu = new QMenu(translator.qString("Field", "Submenu name"));
  toolsGenFieldFieldMenu->addAction(generateFieldChargesAction);
  toolsGenFieldLatticeMenu = new QMenu(translator.qString("Lattice", "Submenu name"));
  toolsGenFieldLatticeMenu->addAction(generateLatticeConnolyAction);
  toolsGenerateFieldMenu = new QMenu(translator.qString("Generate field", "submenu name"));
  toolsGenerateFieldMenu->addMenu(toolsGenFieldLatticeMenu);
  toolsGenerateFieldMenu->addMenu(toolsGenFieldFieldMenu);
  toolsGenerateSurfaceMenu = new QMenu(translator.qString("Generate Surface", "submenu name"));
  toolsGenerateSurfaceMenu->setIcon(QIcon(":/actions/office-chart-polar-stacked.png"));
  toolsGenerateSurfaceMenu->addAction(generateSurfaceConnolyAction);
  toolsMenu = new QMenu(translator.qString("&Tools", "menu name"));
  toolsMenu->addMenu(toolsGenerateSurfaceMenu);
  toolsMenu->addMenu(toolsGenerateFieldMenu);
  toolsMenu->addSeparator();
  toolsMenu->addMenu(toolsInterpolateFieldMenu);
  toolsMenu->addSeparator();
  toolsMenu->addAction(compareFieldsAction);
  toolsMenu->addMenu(toolsCompareMenu);
  toolsMenu->addSeparator();
  toolsMenu->addAction(runScriptAction);
  toolsMenu->addAction(stopProcessAction);
  toolsMenu->addSeparator();
  toolsMenu->addMenu(toolsLoggingMenu);
  toolsMenu->addSeparator();
  toolsMenu->addAction(styleInspectorAction);
  menuBar()->addMenu(toolsMenu);
  viewMenu = new QMenu(translator.qString("&View", "menu name"));
  viewMenu->addAction(viewGeneralToolBarAction);
  viewMenu->addAction(viewEditToolBarAction);
  viewMenu->addAction(viewWindowControlToolBarAction);
  viewMenu->addSeparator();
  viewMenu->addAction(viewLoggerWidgetAction);
  viewMenu->addSeparator();
  menuBar()->addMenu(viewMenu);
  settingsMenu = new QMenu(translator.qString("&Settings", "menu name"));
  settingsMenu->addAction(classicalMenuAction);
  settingsMenu->addAction(professionalMenuAction);
  settingsMenu->addSeparator();
  settingsMenu->addAction(preferencesAction);
  menuBar()->addMenu(settingsMenu);
  windowAlignMenu = new QMenu(translator.qString("Subs' align", "submenu name"));
  windowAlignMenu->addAction(cascadeWindowsAction);
  windowAlignMenu->addAction(tileWindowsAction);
  windowMenu = new QMenu(translator.qString("&Window", "menu name"));
  windowMenu->addAction(minimizeAction);
  windowMenu->addSeparator();
  windowMenu->addAction(subWindowViewAction);
  windowMenu->addAction(tabbedViewAction);
  windowMenu->addSeparator();
  windowMenu->addMenu(windowAlignMenu);
  windowMenu->addSeparator();
  for (QList<QAction *>::iterator i = openedWindowActions.begin(), e = openedWindowActions.end(); i!=e; ++i)
  {
    windowMenu->addAction(*i);
  }
  menuBar()->addMenu(windowMenu);
  helpMenu = new QMenu(translator.qString("&Help", "menu name"));
  helpMenu->addAction(applicationHelpAction);
  helpMenu->addAction(whatIsThisAction);
  helpMenu->addAction(aboutAction);
  menuBar()->addMenu(helpMenu);
}

void MainWindow::setClassicalMenu(){}
void MainWindow::createProfessionalMenu(){}
void MainWindow::setProfessionalMenu(){}

void MainWindow::save()
{
  controller->save( ((SubWindow*)(mdiArea->activeSubWindow()))->wspId() );
}

void MainWindow::saveAll()
{
  controller->saveAll();
};

void MainWindow::recent()
{
  QAction *action = qobject_cast<QAction *>(sender());
  if (action) controller->open(action->data().toString().toStdString());
}

void MainWindow::importStructure() {};
void MainWindow::importLattice() {};
void MainWindow::importField() {};
void MainWindow::importStyle() {};
void MainWindow::importSurface() {};
void MainWindow::exportStructure() {};
void MainWindow::exportLattice() {};
void MainWindow::exportField() {};
void MainWindow::exportStyle() {};
void MainWindow::exportSurface() {};
void MainWindow::exportImage() {};

void MainWindow::closeTab()
{
  if ( QMdiSubWindow *sub = mdiArea->activeSubWindow() ) sub->close();
}

void MainWindow::exit()
{
  mdiArea->closeAllSubWindows(); // this will request saving all documents
  saveSettings();
  controller->exit();
  close();
}

void MainWindow::redo() {};
void MainWindow::undo() {};
void MainWindow::remove() {};
void MainWindow::cut() {};
void MainWindow::copy() {};
void MainWindow::paste() {};
void MainWindow::insertArrow() {};
void MainWindow::insertLine() {};
void MainWindow::insertLabel() {};
void MainWindow::insertText() {};
void MainWindow::translate() {};
void MainWindow::rotate() {};
void MainWindow::scale() {};
void MainWindow::setCpk() {};
void MainWindow::setBS() {};
void MainWindow::setWireframe() {};
void MainWindow::showItems() {}; // show() and hide() controls the window visibility
void MainWindow::hideItems() {};
void MainWindow::selectAll() {};
void MainWindow::unselectAll() {};
void MainWindow::selectNearest() {};
void MainWindow::invertSelection() {};
void MainWindow::selectionBehaviourChanged(QAction *action) {};
void MainWindow::itemInspectorCall() {}; // itemInspector is convenient name for pointer to object
void MainWindow::generateSurfaceConnoly() {};
void MainWindow::generateLatticeConnoly() {};
void MainWindow::generateFieldCharges() {};
void MainWindow::interpolateFieldLinear() {};
void MainWindow::interpolateFieldCubicSplines() {};
void MainWindow::compareFields() {};
void MainWindow::compareStructuresSyncRotation() {};
void MainWindow::compareStructuresOneWindow() {};
void MainWindow::runScript() {};
void MainWindow::loggingStart() {};
void MainWindow::loggingStop() {};
void MainWindow::loggingPause() {};
void MainWindow::generateScript() {};
void MainWindow::stopProcess() {};
void MainWindow::styleInspectorCall() {}; // styleInspector is convenient pointer name

void MainWindow::viewGeneralToolBar()
{
  toolBarFlags ^= General;
  generalToolBar->setVisible(toolBarFlags.testFlag(General));
  viewGeneralToolBarAction->setChecked(toolBarFlags.testFlag(General));
}

void MainWindow::viewEditToolBar()
{
  toolBarFlags ^= Edit;
  editToolBar->setVisible(toolBarFlags.testFlag(Edit));
  viewEditToolBarAction->setChecked(toolBarFlags.testFlag(Edit));
}

void MainWindow::viewWindowControlToolBar()
{
  toolBarFlags ^= WindowControl;
  windowControlToolBar->setVisible(toolBarFlags.testFlag(WindowControl));
  viewWindowControlToolBarAction->setChecked(toolBarFlags.testFlag(WindowControl));
}

void MainWindow::viewLoggerWidget()
{
  widgetFlags ^= LogWidget;
  loggerWidgetDock->setVisible(widgetFlags.testFlag(LogWidget));
  viewLoggerWidgetAction->setChecked(widgetFlags.testFlag(LogWidget));
}

void MainWindow::viewLoggerWidget(bool state)
{
  if (widgetFlags.testFlag(LogWidget) != state)
  {
    widgetFlags ^= LogWidget;
    loggerWidgetDock->setVisible(state);
    viewLoggerWidgetAction->setChecked(state);
  }
}

void MainWindow::preferences() {};
void MainWindow::menuChangeRequested(QAction*) {};

void MainWindow::setViewMode(QAction* action)
{
  QList<QMdiSubWindow*> list = mdiArea->subWindowList();
  if (action == subWindowViewAction)
  {
    mdiArea->setViewMode(QMdiArea::SubWindowView);
    cascadeWindowsAction->setDisabled(false);
    tileWindowsAction->setDisabled(false);
    windowAlignMenu->setDisabled(false);
    for (QList<QMdiSubWindow*>::iterator i = list.begin(), e = list.end(); i!=e; ++i)
      (dynamic_cast<SubWindow*>(*i))->setViewMode(QMdiArea::SubWindowView);
  }
  else
  {
    mdiArea->setViewMode(QMdiArea::TabbedView);
    cascadeWindowsAction->setDisabled(true);
    tileWindowsAction->setDisabled(true);
    windowAlignMenu->setDisabled(true);
    for (QList<QMdiSubWindow*>::iterator i = list.begin(), e = list.end(); i!=e; ++i)
      (dynamic_cast<SubWindow*>(*i))->setViewMode(QMdiArea::TabbedView);

  }
}

void MainWindow::help()
{
  if (!helpBrowser)
  {
    helpBrowser = new QTextBrowser;
    helpBrowser->setSource(QUrl("qrc:/index.html"));
  }
  helpBrowser->show();
};

void MainWindow::whatIsThisRequested() {};

void MainWindow::aboutVizMF()
{
  extern Translator translator;
  QMessageBox::about(this, translator.qString("About VizMF", "about window title"), translator.qString("<h2>VizMF</h2><p><b>Viz</b>ualize <b>M</b>olecular <b>F</b>ields if an application main goal of which is visualization of molecular fields...</p>", "about window text"));
};

void MainWindow::createActions()
{
  extern Translator translator;
  newSessionAction = new QAction(translator.qString("Session", "Menu : File->New->Session"), this);
  newSessionAction->setStatusTip(translator.qString("Create new working session", "action's' status tip"));
  newSessionAction->setWhatsThis(translator.qString("By creating a session you can save the state of apllication with a list of opened documents.", "action's' what's this"));
  newSessionAction->setIcon(QIcon(":/actions/journal-new.png"));
  connect(newSessionAction, SIGNAL(triggered()), this, SLOT(newSession()));
  newDocumentAction = new QAction(translator.qString("Document", "Menu : File->New->Document"), this);
  newDocumentAction->setStatusTip(translator.qString("Create new VizMF document", "action's' status tip"));
  newDocumentAction->setWhatsThis(translator.qString("VizMF document collects molecules, fields and other elements drawn in one tab", "action's what's this"));
  newDocumentAction->setShortcut(QKeySequence(QString("Ctrl+N")));
  newDocumentAction->setIcon(QIcon(":/actions/document-new.png"));
  connect(newDocumentAction, SIGNAL(triggered()), this, SLOT(newDocument()));
  openAction = new QAction(translator.qString("Open", "Menu : File"), this);
  openAction->setStatusTip(translator.qString("Open existing VizMF document", "action's status tip"));
  openAction->setWhatsThis(translator.qString("Just opens VizMF document in a new tab", "actions's what's this"));
  openAction->setShortcut(QKeySequence(QString("Ctrl+O")));
  openAction->setIcon(QIcon(":/actions/document-open.png"));
  connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
  saveAction = new QAction(translator.qString("Save", "Menu : File"), this);
  saveAction->setStatusTip(translator.qString("Save contents of currently active tab", "action status tip"));
  saveAction->setWhatsThis(translator.qString("Records elements from currently active tab into VizMF file", "action what's this"));
  saveAction->setShortcut(QKeySequence(QString("Ctrl+S")));
  saveAction->setIcon(QIcon(":/actions/document-save.png"));
  connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
  saveAllAction = new QAction(translator.qString("Save All", "Menu : File"), this);
  saveAllAction->setStatusTip(translator.qString("Save contents of all tabs", "action status tip"));
  saveAllAction->setWhatsThis(translator.qString("Records elements from all tabs into VizMF files", "action what's this"));
  saveAllAction->setIcon(QIcon(":/actions/document-save-all.png"));
  saveAllAction->setShortcut(QKeySequence(QString("Ctrl+Shift+S")));
  connect(saveAllAction, SIGNAL(triggered()), this, SLOT(saveAll()));
  recentAction[0] = new QAction(translator.qString("Someshit1"), this);
//  connect(recentAction[0], SIGNAL(triggered()), this, SLOT(recent()));
  recentAction[1] = new QAction(translator.qString("Someshit2"), this);
//  connect(recentAction[1], SIGNAL(triggered()), this, SLOT(recent()));
  recentAction[2] = 0;
//  connect(recentAction[2], SIGNAL(triggered()), this, SLOT(recent()));
  recentAction[3] = 0;
//  connect(recentAction[3], SIGNAL(triggered()), this, SLOT(recent()));
  recentAction[4] = 0;
//  connect(recentAction[4], SIGNAL(triggered()), this, SLOT(recent()));
  importStructureAction = new QAction(translator.qString("Structure", "Menu : File->Import->Structure"), this);
  importStructureAction->setStatusTip(translator.qString("Import new molecular data into active tab", "action's status tip"));
  importStructureAction->setWhatsThis(translator.qString("Molecular structure is a set of atoms with coordinates and a row of atomic bonds", "action's what's this"));
  connect(importStructureAction, SIGNAL(triggered()), this, SLOT(importStructure()));
  importLatticeAction = new QAction(translator.qString("Lattice", "Menu : File->Import->Lattice"), this);
  importLatticeAction->setStatusTip(translator.qString("Import new lattice into active tab", "action's status tip"));
  importLatticeAction->setWhatsThis(translator.qString("Lattice is a set of points in which a field can be set or calculted", "action's what's this"));
  connect(importLatticeAction, SIGNAL(triggered()), this, SLOT(importLattice()));
  importFieldAction = new QAction(translator.qString("Field", "Menu : File->Import->Field"), this);
  importFieldAction->setStatusTip(translator.qString("Import new field into active tab", "action's status tip"));
  importFieldAction->setWhatsThis(translator.qString("Field is a distibution of a scalar value in space", "action's what's this"));
  connect(importFieldAction, SIGNAL(triggered()), this, SLOT(importField()));
  importStyleAction = new QAction(translator.qString("Style", "Menu : File->Import->Style"), this);
  importStyleAction->setStatusTip(translator.qString("Import new style into application", "action's status tip"));
  importStyleAction->setWhatsThis(translator.qString("Style is a set of rules of how elements a presented. Imported styles are saved only in <i>sessions</i>.", "action's what's this"));
  connect(importStyleAction, SIGNAL(triggered()), this, SLOT(importStyle()));
  importSurfaceAction = new QAction(translator.qString("Surface", "Menu : File->Import->Surface"), this);
  importSurfaceAction->setStatusTip(translator.qString("Import new surface into active tab", "action's status tip"));
  importSurfaceAction->setWhatsThis(translator.qString("Surface is only a 3D surface, nothing more.", "action's what's this"));
  connect(importSurfaceAction, SIGNAL(triggered()), this, SLOT(importSurface()));
  exportStructureAction = new QAction(translator.qString("Structure", "Menu : File->Export->Structure"), this);
  exportStructureAction->setStatusTip(translator.qString("Export molecular data of currently active tab", "action's status tip"));
  exportStructureAction->setWhatsThis(translator.qString("Molecular structure is a set of atoms with coordinates and a row of atomic bonds", "action's what's this"));
  connect(exportStructureAction, SIGNAL(triggered()), this, SLOT(exportStructure()));
  exportLatticeAction = new QAction(translator.qString("Lattice", "Menu : File->Export->Lattice"), this);
  exportLatticeAction->setStatusTip(translator.qString("Export lattice data of active tab", "action's status tip"));
  exportLatticeAction->setWhatsThis(translator.qString("Lattice is a set of points in which a field can be set or calculted", "action's what's this"));
  connect(exportLatticeAction, SIGNAL(triggered()), this, SLOT(exportLattice()));
  exportFieldAction = new QAction(translator.qString("Field", "Menu : File->Export->Field"), this);
  exportFieldAction->setStatusTip(translator.qString("Export field data of currently active tab", "action's status tip"));
  exportFieldAction->setWhatsThis(translator.qString("Field is a distibution of a scalar value in space", "action's what's this"));
  connect(exportFieldAction, SIGNAL(triggered()), this, SLOT(exportField()));
  exportStyleAction = new QAction(translator.qString("Style", "Menu : File->Export->Style"), this);
  exportStyleAction->setStatusTip(translator.qString("Export custom style into a file", "action's status tip"));
  exportStyleAction->setWhatsThis(translator.qString("Style is a set of rules of how elements a presented. Imported styles are saved only in <i>sessions</i>.", "action's what's this"));
  connect(exportStyleAction, SIGNAL(triggered()), this, SLOT(exportStyle()));
  exportSurfaceAction = new QAction(translator.qString("Surface", "Menu : File->Export->Surface"), this);
  exportSurfaceAction->setStatusTip(translator.qString("Export a surface from currently active tab", "action's status tip"));
  exportSurfaceAction->setWhatsThis(translator.qString("Surface is only a 3D surface, nothing more.", "action's what's this"));
  connect(exportSurfaceAction, SIGNAL(triggered()), this, SLOT(exportSurface()));
  exportImageAction = new QAction(translator.qString("Image", "Menu : File->Export->Image"), this);
  exportImageAction->setStatusTip(translator.qString("Exports currently active tab's contents into an image", "action's status tip"));
  exportImageAction->setWhatsThis(translator.qString("The contents of any tab can be saved as a plain or vector image.", "action's what's this"));
  connect(exportImageAction, SIGNAL(triggered()), this, SLOT(exportImage()));
  closeAction = new QAction(translator.qString("Close tab", "Menu : File->Close tab"), this);
  closeAction->setStatusTip(translator.qString("Close current tab", "action's status tip"));
  closeAction->setIcon(QIcon(":/actions/document-close.png"));
  closeAction->setShortcut(QKeySequence(QString("Ctrl+Q")));
  connect(closeAction, SIGNAL(triggered()), SLOT(closeTab()));
  exitAction = new QAction(translator.qString("Exit", "Menu : File->Exit"), this);
  exitAction->setStatusTip(translator.qString("Exit the application", "action's status tip"));
  exitAction->setIcon(QIcon(":/actions/application-exit.png"));
  connect(exitAction, SIGNAL(triggered()), this, SLOT(exit()));
  redoAction = new QAction(translator.qString("Redo", "Menu : Edit->Redo"), this);
  redoAction->setStatusTip(translator.qString("Redo last action", "action's status tip"));
  redoAction->setWhatsThis(translator.qString("Resores last undone modification of current tab"));
  redoAction->setShortcut(QKeySequence(QString("Ctrl+Y")));
  redoAction->setIcon(QIcon(":/actions/edit-redo.png"));
  connect(redoAction, SIGNAL(triggered()), this, SLOT(redo()));
  undoAction = new QAction(translator.qString("Undo", "Menu : Edit->Undo"), this);
  undoAction->setStatusTip(translator.qString("Undo last action", "action's status tip"));
  undoAction->setWhatsThis(translator.qString("Moves one modification of current tab back"));
  undoAction->setShortcut(QKeySequence(QString("Ctrl+Z")));
  undoAction->setIcon(QIcon(":/actions/edit-undo.png"));
  connect(undoAction, SIGNAL(triggered()), this, SLOT(undo()));
  removeAction = new QAction(translator.qString("Remove", "Menu : Edit->Remove"), this);
  removeAction->setStatusTip(translator.qString("Remove selected objects from the tab", "action's status tip"));
  removeAction->setWhatsThis(translator.qString("Deletes selected items from currently active tab. The items can be restored by <i>Undo</i> action."));
  removeAction->setIcon(QIcon(":/actions/edit-delete.png"));
  removeAction->setShortcut(QKeySequence(QString("Ctrl+Shift+X")));
  connect(removeAction, SIGNAL(triggered()), this, SLOT(remove()));
  cutAction = new QAction(translator.qString("Cut", "Menu : Edit->Cut"), this);
  cutAction->setStatusTip(translator.qString("Cut selected objects from the tab", "action's status tip"));
  cutAction->setWhatsThis(translator.qString("Cut selected items from currently active tab to paste them somewhere else. The items can be restored by <i>Undo</i> action."));
  cutAction->setIcon(QIcon(":/actions/edit-cut.png"));
  cutAction->setShortcut(QKeySequence(QString("Ctrl+X")));
  connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
  copyAction = new QAction(translator.qString("Copy", "Menu : Edit->Copy"), this);
  copyAction->setStatusTip(translator.qString("Copy objects, selected in current tab", "action's status tip"));
  copyAction->setWhatsThis(translator.qString("Copy selected items from currently active tab to paste them somewhere else."));
  copyAction->setIcon(QIcon(":/actions/edit-copy.png"));
  copyAction->setShortcut(QKeySequence(QString("Ctrl+C")));
  connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
  pasteAction = new QAction(translator.qString("Paste", "Menu : Edit->Paste"), this);
  pasteAction->setStatusTip(translator.qString("Paste objects in current tab", "action's status tip"));
  pasteAction->setWhatsThis(translator.qString("Paste copied objects in current tab."));
  pasteAction->setIcon(QIcon(":/actions/edit-paste.png"));
  pasteAction->setShortcut(QKeySequence(QString("Ctrl+V")));
  connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
  insertArrowAction = new QAction(translator.qString("Arrow", "Menu : Edit->Insert->Arrow"), this);
  insertArrowAction->setStatusTip(translator.qString("Insert new arrow object", "action's status tip"));
  insertArrowAction->setWhatsThis(translator.qString("Insert arrow to show something interesting.", "action's what's this"));
  insertArrowAction->setIcon(QIcon(":/actions/insert_arrow.png"));
  connect(insertArrowAction, SIGNAL(triggered()), this, SLOT(insertArrow()));
  insertLineAction = new QAction(translator.qString("Line", "Menu : Edit->Insert->Line"), this);
  insertLineAction->setStatusTip(translator.qString("Insert new line object", "action's status tip"));
  insertLineAction->setWhatsThis(translator.qString("Insert line to show something interesting.", "action's what's this"));
  insertLineAction->setIcon(QIcon(":/actions/insert-horizontal-rule.png"));
  connect(insertLineAction, SIGNAL(triggered()), this, SLOT(insertLine()));
  insertLabelAction = new QAction(translator.qString("Label", "Menu : Edit->Insert->Label"), this);
  insertLabelAction->setStatusTip(translator.qString("Insert new label object", "action's status tip"));
  insertLabelAction->setWhatsThis(translator.qString("Labels are text lines, connected to 3D objects.", "action's what's this"));
  insertLabelAction->setIcon(QIcon(":/actions/insert-link.png"));
  connect(insertLabelAction, SIGNAL(triggered()), this, SLOT(insertLabel()));
  insertTextAction = new QAction(translator.qString("Text", "Menu : Edit->Insert->Text"), this);
  insertTextAction->setStatusTip(translator.qString("Insert new text object", "action's status tip"));
  insertTextAction->setWhatsThis(translator.qString("Text objects are not connected to any 3D element and can be used as name of the picture etc.", "action's what's this"));
  insertTextAction->setIcon(QIcon(":/actions/insert-text.png"));
  connect(insertTextAction, SIGNAL(triggered()), this, SLOT(insertText()));
  translateAction = new QAction(translator.qString("Translate", "Menu : Edit->Transform->Translate"), this);
  translateAction->setStatusTip(translator.qString("Move selected objects", "action's status tip"));
  translateAction->setWhatsThis(translator.qString("Move selected objects in current tab.", "action's what's this"));
  translateAction->setIcon(QIcon(":/actions/transform-move.png"));
  connect(translateAction, SIGNAL(triggered()), this, SLOT(translate()));
  rotateAction = new QAction(translator.qString("Rotate", "Menu : Edit->Transform->Rotate"), this);
  rotateAction->setStatusTip(translator.qString("Rotate selected objects", "action's status tip"));
  rotateAction->setWhatsThis(translator.qString("Rotate selected objects in current tab.", "action's what's this"));
  rotateAction->setIcon(QIcon(":/actions/transform-rotate.png"));
  connect(rotateAction, SIGNAL(triggered()), this, SLOT(rotate()));
  scaleAction = new QAction(translator.qString("Scale", "Menu : Edit->Transform->Scale"), this);
  scaleAction->setStatusTip(translator.qString("Scale selected object", "action's status tip"));
  scaleAction->setWhatsThis(translator.qString("Scale selected objects in current tab.", "action's what's this"));
  scaleAction->setIcon(QIcon(":/actions/transform-scale.png"));
  connect(scaleAction, SIGNAL(triggered()), this, SLOT(scale()));
  setCpkAction = new QAction(translator.qString("CPK", "Menu : Edit->Styles->CPK"), this);
  setCpkAction->setStatusTip(translator.qString("Apply Corey-Pauling-Koltun drawing style to selected objects", "action's status tip"));
  setCpkAction->setWhatsThis(translator.qString("Draws atom as spheres (full VDW radius) and stick bonds.", "action's what's this"));
  connect(setCpkAction, SIGNAL(triggered()), this, SLOT(setCpk()));
  setBSAction = new QAction(translator.qString("BS", "Menu : Edit->Styles->BS"), this);
  setBSAction->setStatusTip(translator.qString("Apply Balls-and-Sticks drawing style to selected objects", "action's status tip"));
  setBSAction->setWhatsThis(translator.qString("Draws atom as spheres and bonds as sticks.", "action's what's this"));
  connect(setBSAction, SIGNAL(triggered()), this, SLOT(setBS()));
  setWireframeAction = new QAction(translator.qString("Wireframe", "Menu : Edit->Styles->Wireframe"), this);
  setWireframeAction->setStatusTip(translator.qString("Apply Wireframe drawing style to selected objects", "action's status tip"));
  setWireframeAction->setWhatsThis(translator.qString("Draws atom as points and bonds as lines.", "action's what's this"));
  connect(setWireframeAction, SIGNAL(triggered()), this, SLOT(setWireframe()));
  showAction = new QAction(translator.qString("Show", "Menu : Edit->Show"), this);
  showAction->setStatusTip(translator.qString("Make selected items visible", "action's atatus tip"));
  showAction->setWhatsThis(translator.qString("Make selected objects to appear on the screen (default for newly loaded objects)."));
  showAction->setIcon(QIcon(":/actions/layer-visible-on.png"));
  connect(showAction, SIGNAL(triggered()), this, SLOT(showItems()));
  hideAction = new QAction(translator.qString("Hide", "Menu : Edit->Hide"), this);
  hideAction->setStatusTip(translator.qString("Make selected items invisible", "action's atatus tip"));
  hideAction->setWhatsThis(translator.qString("Make selected objects to disappear from the screen. Objects are not deleted and can be found in <i>item inspector</i>."));
  hideAction->setIcon(QIcon(":/actions/layer-visible-off.png"));
  connect(hideAction, SIGNAL(triggered()), this, SLOT(hideItems()));
  selectAllAction = new QAction(translator.qString("Select All", "Menu : Selection->SelectAll"), this);
  selectAllAction->setStatusTip(translator.qString("Select everything in current tab", "action's status tip"));
  selectAllAction->setWhatsThis(translator.qString("Selects all objects in currenty active tab."));
  selectAllAction->setShortcut(QKeySequence(QString("Ctrl+A")));
  selectAllAction->setIcon(QIcon(":/actions/edit-select-all.png"));
  connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
  unselectAllAction = new QAction(translator.qString("Unselect all", "Menu : Selection->UnselectAll"), this);
  unselectAllAction->setStatusTip(translator.qString("Unselect everything in current tab", "action's status tip"));
  unselectAllAction->setWhatsThis(translator.qString("Cleares selection."));
  unselectAllAction->setShortcut(QKeySequence(QString("Ctrl+Shift+A")));
  connect(unselectAllAction, SIGNAL(triggered()), this, SLOT(unselectAll()));
  selectNearestAction = new QAction(translator.qString("Select nearest", "Selection->SelectByCriteria->SelectNearest"), this);
  selectNearestAction->setStatusTip(translator.qString("Select nearest elements to already selected", "action's status tip"));
  selectNearestAction->setWhatsThis(translator.qString("Select nearest elements to already selected. \"Nearest\" may be set as absolute distance or some part of VDW radius of selected atoms.", "action's status tip"));
  connect(selectNearestAction, SIGNAL(triggered()), this, SLOT(selectNearest()));
  invertSelectionAction = new QAction(translator.qString("Invert selection", "Selection->InvertSelection"), this);
  invertSelectionAction->setStatusTip(translator.qString("Select unselected and unselect selected objects", "action's status tip"));
  invertSelectionAction->setWhatsThis(translator.qString("Useful when it's easier to select unneeded objects, than needed ones.", "action's status tip"));
  connect(invertSelectionAction, SIGNAL(triggered()), this, SLOT(invertSelection()));
  selectionAppendAction = new QAction(translator.qString("Append", "Selection->Behaviour->Append"), this);
  selectionAppendAction->setStatusTip(translator.qString("Append objects to current selection", "action's status tip"));
  selectionAppendAction->setWhatsThis(translator.qString("While selecting, new objects are added to current selection.", "action's status tip"));
  selectionReplaceAction = new QAction(translator.qString("Replace", "Selection->Behaviour->Replace"), this);
  selectionReplaceAction->setStatusTip(translator.qString("New seleted objects replaces selected ones", "action's status tip"));
  selectionReplaceAction->setWhatsThis(translator.qString("While selecting, new objects become selected and old selection is cleared", "action's status tip"));
  selectionBehaviourActions = new QActionGroup(this);
  selectionBehaviourActions->addAction(selectionAppendAction);
  selectionBehaviourActions->addAction(selectionReplaceAction);
  if (selectionBehaviuorFlags.testFlag(Append)) selectionAppendAction->setChecked(true);
  else if (selectionBehaviuorFlags.testFlag(Replace)) selectionAppendAction->setChecked(false);
  connect(selectionBehaviourActions, SIGNAL(triggered(QAction*)), this, SLOT(selectionBehaviourChanged(QAction*)));
  itemInspectorAction = new QAction(translator.qString("Item Inspector", "Selection->Behaviour->ItemInspector"), this);
  itemInspectorAction->setStatusTip(translator.qString("Open Item Inspector", "action's status tip"));
  itemInspectorAction->setWhatsThis(translator.qString("Open special dialog where all objects of current tab are listed.", "action's status tip"));
  connect(itemInspectorAction, SIGNAL(triggered()), this, SLOT(itemInspectorCall()));
  generateSurfaceConnolyAction = new QAction(translator.qString("Connoly", "Menu : Tools->GenerateSurface->Connoly"), this);
  generateSurfaceConnolyAction->setStatusTip(translator.qString("Generate molecular surface by Connoly's algorithm", "action's status tip"));
  generateSurfaceConnolyAction->setWhatsThis(translator.qString("", "action's what's this"));  // WRITE DESCR OF ALGORITHM
  connect(generateSurfaceConnolyAction, SIGNAL(triggered()), this, SLOT(generateSurfaceConnoly()));
  generateLatticeConnolyAction = new QAction(translator.qString("Connoly", "Menu : Tools->GenerateLattice->Connoly"), this);
  generateLatticeConnolyAction->setStatusTip(translator.qString("Generate lattice by Connoly's algorithm", "action's status tip"));
  generateLatticeConnolyAction->setWhatsThis(translator.qString("", "action's what's this"));  // WRITE DESCR OF ALGORITHM
  connect(generateLatticeConnolyAction, SIGNAL(triggered()), this, SLOT(generateLatticeConnoly()));
  generateFieldChargesAction = new QAction(translator.qString("Charges", "Menu : Tools->GenerateField->Charges"), this);
  generateFieldChargesAction->setStatusTip(translator.qString("Generate field on the base of atomic charges", "action's status tip"));
  generateFieldChargesAction->setWhatsThis(translator.qString("Use atomic charges as the only sources of electrostatic field", "action's what's this"));  // WRITE DESCR OF ALGORITHM
  connect(generateFieldChargesAction, SIGNAL(triggered()), this, SLOT(generateFieldCharges()));
  interpolateFieldLinearAction = new QAction(translator.qString("Linear", "Menu : Tools->InterpolateField->Linear"), this);
  interpolateFieldLinearAction->setStatusTip(translator.qString("Interpolate field by linear approximation", "action's status tip"));
  interpolateFieldLinearAction->setWhatsThis(translator.qString("Linear interpolation of the field. This is the fastest interpolation approach.", "action's what's this"));  // WRITE DESCR OF ALGORITHM
  interpolateFieldLinearAction->setIcon(QIcon(":/actions/draw-lines.png"));
  connect(interpolateFieldLinearAction, SIGNAL(triggered()), this, SLOT(interpolateFieldLinear()));
  interpolateFieldCubicSplinesAction = new QAction(translator.qString("Cubic Splines", "Menu : Tools->InterpolateField->CubicSplines"), this);
  interpolateFieldCubicSplinesAction->setStatusTip(translator.qString("Interpolate field by cubic splines approximation", "action's status tip"));
  interpolateFieldCubicSplinesAction->setWhatsThis(translator.qString("Cubic splines interpolation of the field.", "action's what's this"));  // WRITE DESCR OF ALGORITHM
  interpolateFieldCubicSplinesAction->setIcon(QIcon(":/actions/draw-bezier-curves.png"));
  connect(interpolateFieldCubicSplinesAction, SIGNAL(triggered()), this, SLOT(interpolateFieldCubicSplines()));
  compareFieldsAction = new QAction(translator.qString("Compare fields", "Tools->CompareFields"), this);
  compareFieldsAction->setStatusTip(translator.qString("Compare fields in one tab", "action's status tip"));
  compareFieldsAction->setWhatsThis(translator.qString("Tools for field comparison e. g. display difference between fields", "action's what's this"));
  connect(compareFieldsAction, SIGNAL(triggered()), this, SLOT(compareFields()));
  compareStructuresSyncRotationAction = new QAction(translator.qString("Sync Rotation", "Tools->CompareStructures->SyncRotation"), this);
  compareStructuresSyncRotationAction->setStatusTip(translator.qString("Syncronously rotate two (or more) structures", "action's status tip"));
  compareStructuresSyncRotationAction->setWhatsThis(translator.qString("Syncronously rotate two (or more) structures in different tabs", "action's what's this"));
  connect(compareStructuresSyncRotationAction, SIGNAL(triggered()), this, SLOT(compareStructuresSyncRotation()));
  compareStructuresOneWindowAction = new QAction(translator.qString("In one tab", "Tools->CompareStructures->InOneTab"), this);
  compareStructuresOneWindowAction->setStatusTip(translator.qString("Put structures in one tab to compare them", "action's status tip"));
  compareStructuresOneWindowAction->setWhatsThis(translator.qString("Put different structures in one tab trying to match analogous elements", "action's what's this"));
  connect(compareStructuresOneWindowAction, SIGNAL(triggered()), this, SLOT(compareStructuresOneWindow()));
  runScriptAction = new QAction(translator.qString("Run Script", "Menu : Tools->RunScript"), this);
  runScriptAction->setStatusTip(translator.qString("Execute script", "action's status tip"));
  runScriptAction->setWhatsThis(translator.qString("Open and execute a set of recorded operations.", "action's what's this"));
  runScriptAction->setIcon(QIcon(":/actions/media-playback-start.png"));
  connect(runScriptAction, SIGNAL(triggered()), this, SLOT(runScript()));
  loggingStartAction = new QAction(translator.qString("Start", "Menu : Tools->Logging->Start"), this);
  loggingStartAction->setStatusTip(translator.qString("Start writing log to file", "action's status tip"));
  loggingStartAction->setWhatsThis(translator.qString("Open file and start recording what's happening in program.", "action's what's this"));
  loggingStartAction->setIcon(QIcon(":/actions/media-record.png"));
  connect(loggingStartAction, SIGNAL(triggered()), this, SLOT(loggingStart()));
  loggingStopAction = new QAction(translator.qString("Stop", "Menu : Tools->Logging->Stop"), this);
  loggingStopAction->setStatusTip(translator.qString("Stop writing log to file", "action's status tip"));
  loggingStopAction->setWhatsThis(translator.qString("Stop recording and save log file.", "action's what's this"));
  loggingStopAction->setIcon(QIcon(":/actions/media-playback-stop.png"));
  connect(loggingStopAction, SIGNAL(triggered()), this, SLOT(loggingStop()));
  loggingPauseAction = new QAction(translator.qString("Pause", "Menu : Tools->Logging->Pause"), this);
  loggingPauseAction->setStatusTip(translator.qString("Pause recording log", "action's status tip"));
  loggingPauseAction->setWhatsThis(translator.qString("Pause recording to resume later.", "action's what's this"));
  loggingPauseAction->setIcon(QIcon(":/actions/media-playback-pause.png"));
  connect(loggingPauseAction, SIGNAL(triggered()), this, SLOT(loggingPause()));
  generateScriptAction = new QAction(translator.qString("Generate script", "Menu : Tools->Logging->GenerateScript"), this);
  generateScriptAction->setStatusTip(translator.qString("Try to generate script from log file", "action's status tip"));
  generateScriptAction->setWhatsThis(translator.qString("Tries to generate sequence of actions from log file and record them as a script.", "action's what's this"));
  generateScriptAction->setIcon(QIcon(":/actions/run-build-install.png"));
  connect(generateScriptAction, SIGNAL(triggered()), this, SLOT(generateScript()));
  stopProcessAction = new QAction(translator.qString("Stop process", "Menu : Tools->StopProcess"), this);
  stopProcessAction->setStatusTip(translator.qString("Try to stop currently running program's calculation process", "action's status tip"));
  stopProcessAction->setWhatsThis(translator.qString("Try to stop currently running program's calculation process. It can be generation of new lattice or surface, interpolation of field, etc.", "action's what's this"));
  stopProcessAction->setIcon(QIcon(":/actions/process-stop.png"));
  connect(stopProcessAction, SIGNAL(triggered()), this, SLOT(stopProcess()));
  styleInspectorAction = new QAction(translator.qString("Style Inspector", "Menu : Tools->StyleInspector"), this);
  styleInspectorAction->setStatusTip(translator.qString("Open style inspector dialog", "action's status tip"));
  styleInspectorAction->setWhatsThis(translator.qString("A dialog, where you can change existing drawing styles as far as create new ones.", "action's what's this"));
  connect(styleInspectorAction, SIGNAL(triggered()), this, SLOT(styleInspectorCall()));
  viewGeneralToolBarAction = new QAction(translator.qString("General Toolbar", "Menu : View->GeneralToolBar"), this);
  viewGeneralToolBarAction->setStatusTip(translator.qString("Show/Hide general toolbar", "action's status tip"));
  viewGeneralToolBarAction->setWhatsThis(translator.qString("Shows and hides general toolbar.", "action's what's this"));
  viewGeneralToolBarAction->setCheckable(true);
  viewGeneralToolBarAction->setChecked(toolBarFlags.testFlag(General));
  connect(viewGeneralToolBarAction, SIGNAL(triggered()), this, SLOT(viewGeneralToolBar()));
  viewEditToolBarAction = new QAction(translator.qString("Edit Toolbar", "Menu : View->EditToolBar"), this);
  viewEditToolBarAction->setStatusTip(translator.qString("Show/Hide edit toolbar", "action's status tip"));
  viewEditToolBarAction->setWhatsThis(translator.qString("Shows and hides edit toolbar.", "action's what's this"));
  viewEditToolBarAction->setCheckable(true);
  viewEditToolBarAction->setChecked(toolBarFlags.testFlag(Edit));
  connect(viewEditToolBarAction, SIGNAL(triggered()), this, SLOT(viewEditToolBar()));
  viewWindowControlToolBarAction = new QAction(translator.qString("Window Control Toolbar", "Menu : View->WindowControl"), this);
  viewWindowControlToolBarAction->setStatusTip(translator.qString("Show/Hide window control toolbar", "action's status tip"));
  viewWindowControlToolBarAction->setWhatsThis(translator.qString("Shows and hides vindow control toolbar.", "action's what's this"));
  viewWindowControlToolBarAction->setCheckable(true);
  viewWindowControlToolBarAction->setChecked(toolBarFlags.testFlag(WindowControl));
  connect(viewWindowControlToolBarAction, SIGNAL(triggered()), this, SLOT(viewWindowControlToolBar()));
  viewLoggerWidgetAction = new QAction(translator.qString("Logger", "Menu : View->WindowControl"), this);
  viewLoggerWidgetAction->setStatusTip(translator.qString("Show/Hide window control toolbar", "action's status tip"));
  viewLoggerWidgetAction->setWhatsThis(translator.qString("Shows and hides vindow control toolbar.", "action's what's this"));
  viewLoggerWidgetAction->setCheckable(true);
  viewLoggerWidgetAction->setChecked(widgetFlags.testFlag(LogWidget));
  connect(viewLoggerWidgetAction, SIGNAL(triggered()), this, SLOT(viewLoggerWidget()));
  preferencesAction = new QAction(translator.qString("Preferences", "Menu : Settings->Preferences"), this);
  preferencesAction->setStatusTip(translator.qString("Open application's preferences dialog", "action's status tip"));
  preferencesAction->setWhatsThis(translator.qString("Open a dialog where you can fine tune application behaviour as you like.", "action's what's this"));
  preferencesAction->setIcon(QIcon(":/actions/configure.png"));
  connect(preferencesAction, SIGNAL(triggered()), this, SLOT(preferences()));
  classicalMenuAction = new QAction(translator.qString("Classical menu", "Menu : Settings->ClassicalMenu"), this);
  classicalMenuAction->setStatusTip(translator.qString("Switch to classical menu", "action's status tip"));
  classicalMenuAction->setWhatsThis(translator.qString("Switch to classical menu: File Edit Selection etc", "action's what's this"));
  classicalMenuAction->setCheckable(true);
  professionalMenuAction = new QAction(translator.qString("Professional menu", "Menu : Settings->ProfessionalMenu"), this);
  professionalMenuAction->setStatusTip(translator.qString("Switch to professional menu", "action's status tip"));
  professionalMenuAction->setWhatsThis(translator.qString("Switch to professional menu: File SelectionStructure Field etc", "action's what's this"));
  professionalMenuAction->setCheckable(true);
  menuChangeRequestActions = new QActionGroup(this);
  menuChangeRequestActions->addAction(classicalMenuAction);
  menuChangeRequestActions->addAction(professionalMenuAction);
  switch (menuType)
  {
  case ClassicalMenu :
    classicalMenuAction->setChecked(true);
    break;
  case ProfessionalMenu :
    professionalMenuAction->setChecked(true);
  }
  connect(menuChangeRequestActions, SIGNAL(triggered(QAction*)), this, SLOT(menuChangeRequested(QAction*)));
  minimizeAction = new QAction(translator.qString("Minimize", "Menu : Settings->Minimize"), this);
  minimizeAction->setStatusTip(translator.qString("Minimize main window", "action's status tip"));
  minimizeAction->setWhatsThis(translator.qString("Minimize main window to task bar.", "action's what's this"));
  connect(minimizeAction, SIGNAL(triggered()), this, SLOT(showMinimized()));
  cascadeWindowsAction = new QAction(translator.qString("Cascade", "Menu : Window->Align->Cascade"), this);
  cascadeWindowsAction->setStatusTip(translator.qString("Align opened documents in cascade", "action's status tip"));
  cascadeWindowsAction->setWhatsThis(translator.qString("Align opened documents in cascade", "action's what's this"));
  connect(cascadeWindowsAction, SIGNAL(triggered()), mdiArea, SLOT(cascadeSubWindows()));
  tileWindowsAction = new QAction(translator.qString("Tile", "Menu : Window->Align->Tile"), this);
  tileWindowsAction->setStatusTip(translator.qString("Align opened documents in tile", "action's status tip"));
  tileWindowsAction->setWhatsThis(translator.qString("Align opened documents in tile", "action's what's this"));
  connect(tileWindowsAction, SIGNAL(triggered()), mdiArea, SLOT(tileSubWindows()));
  subWindowViewAction = new QAction(translator.qString("Sub Windows"), this);
  subWindowViewAction->setStatusTip(translator.qString("View opened documents in small windows."));
  subWindowViewAction->setWhatsThis(translator.qString("View opened documents in small windows."));
  subWindowViewAction->setCheckable(true);
  tabbedViewAction = new QAction(translator.qString("Tabs"), this);
  tabbedViewAction->setStatusTip(translator.qString("View opened documents in tabs."));
  tabbedViewAction->setWhatsThis(translator.qString("View opened documents in tabs."));
  tabbedViewAction->setCheckable(true);
  viewModeGroup = new QActionGroup(this);
  viewModeGroup->addAction(tabbedViewAction);
  viewModeGroup->addAction(subWindowViewAction);
  if (tabbedViewFlag) tabbedViewAction->setChecked(true); else subWindowViewAction->setChecked(true);
  connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*)));
  openedWindowActions = QList<QAction *>();
  applicationHelpAction = new QAction(translator.qString("Contents", "Menu : Help->Contents"), this);
  applicationHelpAction->setStatusTip(translator.qString("Show application's help", "action's status tip"));
  applicationHelpAction->setWhatsThis(translator.qString("Show broad information about the application.", "action's what's this"));
  applicationHelpAction->setIcon(QIcon(":/actions/help-contents.png"));
  applicationHelpAction->setShortcut(QKeySequence(QString("F1")));
  connect(applicationHelpAction, SIGNAL(triggered()), this, SLOT(help()));
  whatIsThisAction = new QAction(translator.qString("What Is This", "Menu : Help->WhatIsThis"), this);
  whatIsThisAction->setStatusTip(translator.qString("Click on any object to see brief description", "action's status tip"));
  whatIsThisAction->setWhatsThis(translator.qString("Click here to be able reading such messages.", "action's what's this"));
  connect(whatIsThisAction, SIGNAL(triggered()), this, SLOT(whatIsThisRequested()));
  aboutAction = new QAction(translator.qString("About VizMF", "Menu : Help->AboutVizMF"), this);
  aboutAction->setStatusTip(translator.qString("Show breif information about this application", "action's status tip"));
  aboutAction->setWhatsThis(translator.qString("Show breif information about this application.", "action's what's this"));
  connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutVizMF()));
}
